FROM python:3.9-slim as python-base

ENV PIP_NO_CACHE_DIR=off \
    PIP_DISABLE_PIP_VERSION_CHECK=on \
    PIP_DEFAULT_TIMEOUT=100 \
    POETRY_PATH=/opt/poetry \
    VENV_PATH=/opt/venv
ENV PATH="$POETRY_PATH/bin:$VENV_PATH/bin:$PATH"

FROM python-base as poetry
ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN sed -i "s@http://deb.debian.org@https://mirrors.163.com@g" /etc/apt/sources.list
RUN apt-get update \
    && sh -c '/bin/echo -e "y" | apt-get install git curl' &&apt-get clean \
    # install poetry - uses $POETRY_VERSION internally
    && curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | POETRY_HOME=$POETRY_PATH python3 - \
#    && . $POETRY_PATH/env \
    && poetry --version \
    # cleanup
    && rm -rf /var/lib/apt/lists/*

FROM poetry as runtime
WORKDIR /project
RUN python -m pip install --upgrade pip
COPY poetry.lock pyproject.toml ./
RUN poetry config virtualenvs.create false && poetry install
COPY . .

EXPOSE 8000
